package eduware.util.crypt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;

import eduware.util.exception.ChaocipherException;

/**
 * This class provides a BufferedReader that is extended by an encryption
 * support basing on Chaocipher.
 * 
 * @author Florian Bausch
 * 
 */
public class EncryptedReader extends BufferedReader {

	/**
	 * An instance of Chaocipher for decrypting the file.
	 */
	private Chaocipher cc;

	/**
	 * Creates an EncryptedReader.
	 * 
	 * @param arg0
	 *            A reader.
	 */
	public EncryptedReader(Reader arg0) throws ChaocipherException {
		super(arg0);
		try {
			cc = new Chaocipher();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Decrypt the next line.
	 * 
	 * @return Returns an decrypted line from an encrypted Reader.
	 * @throws IOException
	 */
	public String readLine() throws IOException{
		return cc.decrypt(super.readLine());
	}

}
